<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>修改密码</title>
        <link rel="stylesheet" type="text/css" href="assets/lib/layui/css/layui.css" />

        <style type="text/css">
            .layui-form {
                padding: 15px;
            }
        </style>
    </head>
    <body>
        <form class="layui-form" id="reg_form" action="">
            <div class="title">

            </div>
            <div class="layui-form-item">
                <input type="text" name="oldPwd" lay-verify="required" autocomplete="off" placeholder="请输入原密码" class="layui-input username">
            </div>
            <div class="layui-form-item">
                <input type="password" name="newPwd" lay-verify="required|password" autocomplete="off" placeholder="请输入密码"
                    class="layui-input password1">
            </div>
            <div class="layui-form-item">
                <input type="password" id="repassword" lay-verify="required|repassword|password" autocomplete="off"
                    placeholder="请确认密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <button type="button" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="editPwd">修改密码</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>

        </form>
        <script type="text/javascript" src="assets/lib/layui/layui.js">

        </script>
        <script src="assets/js/baseUrl.js"></script>
        <script type="text/javascript">
            layui.use(['jquery', 'form', 'layer'], function() {
                let $ = layui.jquery;
                let form = layui.form;
                let layer = layui.layer;

                form.on('submit(editPwd)', function(data) {
                    let field = data.field; //获取表单数据
                    $.ajax({
                        method: 'POST',
                        url: '/my/updatepwd',
                        data: field,
                        success: function(result) {
                            if (result.status == 0) {
                                console.log(result);

                                layer.msg('修改成功');
                            }


                        }

                    })
                    return false; //阻止表单默认提交
                })

                //自定义验证规则
                form.verify({

                    password: [
                        /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
                    ],
                    repassword: function(value) { //value：表单的值、item：表单的DOM对象
                        let password = $('.password1').val();
                        if (value != password) {
                            return '两次密码不一致';

                        }
                    }
                });

            });
        </script>
    </body>
</html>
